//
//  UserInfoCredit.m
//  BrushFace
//
//  Created by timer_q on 16/1/24.
//  Copyright © 2016年 Zzz. All rights reserved.
//

#import "UserInfoCredit.h"
#import "NavHelper.h"

@interface UserInfoCredit ()

@end

@implementation UserInfoCredit

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self.navBar setTitle:@"信用提升"];
    [self.navBar setLeftBtn:NAV_BAR_LEFT_BTN_TYPE_WHITE];
    [self.navBar setNavBackColor:[UIColor clearColor]];
    
    
    NSString *requestStr = [NSString stringWithFormat:@"%@/user/getusercreditinfo4app.json",SERVICE_ADRESS];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer = [[AFHTTPResponseSerializer alloc] init];
    [manager GET:requestStr parameters:nil success:^(AFHTTPRequestOperation * _Nonnull operation, id  _Nonnull responseObject) {
        NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
        if ([[NSString stringWithFormat:@"%@",json[@"totalpercent"]] integerValue]==100) {
            self.upedView.hidden = NO;
            self.upingView.hidden = YES;
            _upedEndLabel.text = [NSString stringWithFormat:@"%ld",[[NSString stringWithFormat:@"%@",json[@"amount"]] integerValue]+1000];
        }else{
            self.upedView.hidden = YES;
            self.upingView.hidden = NO;
            _currentLabel.text = [NSString stringWithFormat:@"%@",json[@"amount"]];
            _imgEndLabel.text = [NSString stringWithFormat:@"%ld",[[NSString stringWithFormat:@"%@",json[@"amount"]] integerValue]+1000];
            _presentLabel.text = [NSString stringWithFormat:@"%@%%",json[@"totalpercent"]];
        }
        
        
    } failure:^(AFHTTPRequestOperation * _Nullable operation, NSError * _Nonnull error) {
        
    }];
}
- (void)viewWillAppear:(BOOL)animated{
    NSString *requestStr = [NSString stringWithFormat:@"%@/user/getusercreditinfo4app.json",SERVICE_ADRESS];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer = [[AFHTTPResponseSerializer alloc] init];
    [manager GET:requestStr parameters:nil success:^(AFHTTPRequestOperation * _Nonnull operation, id  _Nonnull responseObject) {
        NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
        if ([[NSString stringWithFormat:@"%@",json[@"totalpercent"]] integerValue]==100) {
            self.upedView.hidden = NO;
            self.upingView.hidden = YES;
            _upedEndLabel.text = [NSString stringWithFormat:@"%ld",[[NSString stringWithFormat:@"%@",json[@"amount"]] integerValue]];
        }else{
            self.upedView.hidden = YES;
            self.upingView.hidden = NO;
            _currentLabel.text = [NSString stringWithFormat:@"%@",json[@"amount"]];
            _imgEndLabel.text = [NSString stringWithFormat:@"%ld",[[NSString stringWithFormat:@"%@",json[@"amount"]] integerValue]+1000];
            _presentLabel.text = [NSString stringWithFormat:@"%@%%",json[@"totalpercent"]];
        }
        
        
    } failure:^(AFHTTPRequestOperation * _Nullable operation, NSError * _Nonnull error) {
        
    }];

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)toAddUserInfo:(id)sender {
    [NavHelper gotoUserInfoVC];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
